//
//  MLUser.m
//  Molian
//
//  Created by wan song on 20/11/14.
//  Copyright (c) 2014 memeda. All rights reserved.
//

#import "MLUser.h"

#define CONSTELLATION_MOJIE @"摩羯座"
#define CONSTELLATION_SHUIPING @"水瓶座"
#define CONSTELLATION_SHUANGYU @"双鱼座"
#define CONSTELLATION_BAIYANG @"白羊座"
#define CONSTELLATION_JINGNIU @"金牛座"
#define CONSTELLATION_SHUANGZI @"双子座"
#define CONSTELLATION_JUXIE @"巨蟹座"
#define CONSTELLATION_SHIZI @"狮子座"
#define CONSTELLATION_CHUNV @"处女座"
#define CONSTELLATION_TIANCHENG @"天秤座"
#define CONSTELLATION_TIANXIE @"天蝎座"
#define CONSTELLATION_SHESHOU @"射手座"


@implementation MLUser

@dynamic molianId;
@dynamic nickname;
@dynamic subAvatar;
@dynamic avatar;
@dynamic birthday;
@dynamic gender;
@dynamic level;
@dynamic status;
@dynamic type;
@dynamic balance;
@dynamic height;
@dynamic weight;
@dynamic likeCount;
@dynamic figure;
@dynamic emotion;
//@dynamic like;
//@dynamic belong;
@dynamic selectCity;
@dynamic language;
@dynamic job;
@dynamic intro;
@dynamic like_tags;
//@dynamic dislike_tags;
//@dynamic call_tags;
//@dynamic called_tags;
//@dynamic willing_tags;
@dynamic location_province;
@dynamic location_city;
@dynamic location_district;
@dynamic price;
@dynamic background;
@dynamic lastLogin;
//@dynamic special;
@dynamic isHasVoice;
@dynamic isUserInited;
@dynamic belongToArticle;
//用户被举报的次数
@dynamic reportCount;
//禁言开始时间
@dynamic forbiddenTime;
@dynamic notifyPhoneNum;
@dynamic signCount;
@dynamic checkapp;
@dynamic realAuthentic;
//@dynamic interestTopic;
@dynamic sweetheartTime;
//@dynamic want_tags;
@dynamic ideal_tags;
@dynamic complaintCount;
@dynamic school;
@dynamic impress;
//@dynamic selectCity;
@dynamic weChat;
@dynamic isPay;
+ (NSString *)parseClassName {
    return @"_User";
}

// 根据用户生日获取星座
- (NSString *)getUserConstellation {
    
    // 根据日期获得星座的系统id
    NSString *constellation;
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MM"];
    int i_month=0;
    NSString *theMonth = [dateFormat stringFromDate:self.birthday];
    if([[theMonth substringToIndex:0] isEqualToString:@"0"]){
        i_month = [[theMonth substringFromIndex:1] intValue];
    }else{
        i_month = [theMonth intValue];
    }
    
    [dateFormat setDateFormat:@"dd"];
    int i_day=0;
    NSString *theDay = [dateFormat stringFromDate:self.birthday];
    if([[theDay substringToIndex:0] isEqualToString:@"0"]){
        i_day = [[theDay substringFromIndex:1] intValue];
    }else{
        i_day = [theDay intValue];
    }
    switch (i_month) {
        case 1:
            if(i_day>=20 && i_day<=31){
                constellation = CONSTELLATION_SHUIPING;
            }
            if(i_day>=1 && i_day<=19){
                constellation = CONSTELLATION_MOJIE;
            }
            break;
        case 2:
            if(i_day>=1 && i_day<=18){
                constellation = CONSTELLATION_SHUIPING;
            }
            if(i_day>=19 && i_day<=31){
                constellation = CONSTELLATION_SHUANGYU;
            }
            break;
        case 3:
            if(i_day>=1 && i_day<=20){
                constellation = CONSTELLATION_SHUANGYU;
            }
            if(i_day>=21 && i_day<=31){
                constellation = CONSTELLATION_BAIYANG;
            }
            break;
        case 4:
            if(i_day>=1 && i_day<=19){
                constellation = CONSTELLATION_BAIYANG;
            }
            if(i_day>=20 && i_day<=31){
                constellation = CONSTELLATION_JINGNIU;
            }
            break;
        case 5:
            if(i_day>=1 && i_day<=20){
                constellation = CONSTELLATION_JINGNIU;
            }
            if(i_day>=21 && i_day<=31){
                constellation = CONSTELLATION_SHUANGZI;
            }
            break;
        case 6:
            if(i_day>=1 && i_day<=21){
                constellation = CONSTELLATION_SHUANGZI;
            }
            if(i_day>=22 && i_day<=31){
                constellation = CONSTELLATION_JUXIE;
            }
            break;
        case 7:
            if(i_day>=1 && i_day<=22){
                constellation = CONSTELLATION_JUXIE;
            }
            if(i_day>=23 && i_day<=31){
                constellation = CONSTELLATION_SHIZI;
            }
            break;
        case 8:
            if(i_day>=1 && i_day<=22){
                constellation = CONSTELLATION_SHIZI;
            }
            if(i_day>=23 && i_day<=31){
                constellation = CONSTELLATION_CHUNV;
            }
            break;
        case 9:
            if(i_day>=1 && i_day<=22){
                constellation = CONSTELLATION_CHUNV;
            }
            if(i_day>=23 && i_day<=31){
                constellation = CONSTELLATION_TIANCHENG;
            }
            break;
        case 10:
            if(i_day>=1 && i_day<=23){
                constellation = CONSTELLATION_TIANCHENG;
            }
            if(i_day>=24 && i_day<=31){
                constellation = CONSTELLATION_TIANXIE;
            }
            break;
        case 11:
            if(i_day>=1 && i_day<=21){
                constellation = CONSTELLATION_TIANXIE;
            }
            if(i_day>=22 && i_day<=31){
                constellation = CONSTELLATION_SHESHOU;
            }
            break;
        case 12:
            if(i_day>=1 && i_day<=21){
                constellation = CONSTELLATION_SHESHOU;
            }
            if(i_day>=21 && i_day<=31){
                constellation = CONSTELLATION_MOJIE;
            }
            break;
    }
    return constellation;
}



- (NSUInteger)getUserAge {
    // 当前日期
    NSDateComponents *todayComponents = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
    NSInteger thisYear = [todayComponents year];
    NSInteger thisMonth = [todayComponents month];
    NSInteger thisDay = [todayComponents day];
    
    NSDateComponents *pastComponents = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:self.birthday];
    NSInteger pastYear = [pastComponents year];
    NSInteger pastMonth = [pastComponents month];
    NSInteger pastDay = [pastComponents day];
    
    NSInteger deltaYear = thisYear - pastYear;
    NSInteger deltaMonth = thisMonth - pastMonth;
    NSInteger deltaDay = thisDay- pastDay;
    if (deltaYear < 0) {
        return 0;
    }
    
    if (deltaMonth > 0) {
        return deltaYear + 1;
    } else if (deltaMonth < 0) {
        return deltaYear;
    } else {
        if (deltaDay > 0) {
            return deltaYear + 1;
        } else {
            return deltaYear;
        }
    }
}

@end
